<?php
function bbcode($var) {
	$var = preg_replace ( '#\[code\](.*?)\[/code\]#si', '<div class="quote" style="color:blue">Copy Mã</div><textarea cols="15" rows="2" class="baiviet" style="color:#777777;text-align:left;">\1</textarea><br>', $var );
	$var = preg_replace ( '#\[vblue\](.*?)\[/vblue\]#si', '<span style="text-shadow: 1px 3px 9px blue;">\1</span>', $var );
	$var = preg_replace ( '#\[vgreen\](.*?)\[/vgreen\]#si', '<span style="text-shadow: 1px 3px 9px green;">\1</span>', $var );
	$var = preg_replace ( '#\[vred\](.*?)\[/vred\]#si', '<span style="text-shadow: 1px 3px 9px red;">\1</span>', $var );
	$var = preg_replace ( '#\[b\](.*?)\[/b\]#si', '<span style="font-weight: bold;">\1</span>', $var );
	$var = preg_replace ( '#\[i\](.*?)\[/i\]#si', '<span style="font-style:italic;">\1</span>', $var );
	$var = preg_replace ( '#\[u\](.*?)\[/u\]#si', '<span style="text-decoration:underline;">\1</span>', $var );
	$var = preg_replace ( '#\[s\](.*?)\[/s\]#si', '<span style="text-decoration: line-through;">\1</span>', $var );
	$var = preg_replace ( '#\[img=(.+?)\]#is', '<a href="\1"><img src="\1" alt="Hình" border="0" width="120"/></a><br/>', $var );
	$var = preg_replace ( '#\[img](.+?)\[/img]#is', '<a href="\1"><img src="\1" alt="Hình" border="0" width="120"/></a><br/>', $var );
	$var = preg_replace ( '#\[img=(.+?)\][/img]#is', '<a href="\1"><img src="\1" alt="Hình" border="0" width="120"/></a><br/>', $var );
	$var = preg_replace ( '#\[COLOR=(.+?)\](.+?)\[/COLOR\]#is', '<font style="color:\1;">\2</font>', $var );
	$var = preg_replace ( '#\[c=(.+?)\](.*?)\[/c\]#si', '<div class="quote"><b style="color:blue;">\1 Viết:</b><br>\2</div>', $var );
	$var = preg_replace ( '#\[color=(.+?)\](.+?)\[/color\]#is', '<font style="color:\1;">\2</font>', $var );
	$var = preg_replace ( '#\[br\]#is', '<br />', $var );
	$var = preg_replace ( '#\[BR\]#is', '<br />', $var );
	$var = preg_replace ( '#\[SIZE=(.+?)\](.+?)\[/SIZE\]#is', '<font style="font-size:\1;">\2</font>', $var );
	$var = preg_replace ( '#\[size=(.+?)\](.+?)\[/size\]#is', '<font style="font-size:\1;">\2</font>', $var );
	$var = preg_replace ( '#\[FONT=(.+?)\](.+?)\[/FONT\]#is', '<font face="\1">\2</font>', $var );
	$var = preg_replace ( '#\[font=(.+?)\](.+?)\[/font\]#is', '<font face="\1">\2</font>', $var );
	$var = preg_replace ( "#\[url=(.+?)\](.+?)\[/url\]#is", "" . ("<a href=\"\\1\">\\2</a>") . "", $var );
	$var = preg_replace ( "#\[URL=(.+?)\](.+?)\[/URL\]#is", "" . ("<a href=\"\\1\">\\2</a>") . "", $var );
	$var = preg_replace ( '#\[phai\](.+?)\[/phai\]#is', '<div align="right">\1</div>', $var );
	$var = preg_replace ( '#\[center\](.+?)\[/center\]#is', '<div align="center">\1</div>', $var );
	$var = preg_replace ( '#\[CENTER\](.+?)\[/CENTER\]#is', '<div align="center">\1</div>', $var );
	$var = preg_replace ( '#\[LEFT\](.+?)\[/LEFT\]#is', '<div align="left">\1</div>', $var );
	$var = preg_replace ( '#\[left\](.+?)\[/left\]#is', '<div align="left">\1</div>', $var );
	$var = preg_replace ( '#\[right\](.+?)\[/right\]#is', '<div align="right">\1</div>', $var );
	$var = preg_replace ( '#\[RIGHT\](.+?)\[/RIGHT\]#is', '<div align="right">\1</div>', $var );
	$var = preg_replace ( '#\[trai\](.+?)\[/trai\]#is', '<div align="left">\1</div>', $var );
	$var = preg_replace ( '#\[giua\](.+?)\[/giua\]#is', '<div align="center">\1</div>', $var );
	$var = preg_replace ( '#\[red\](.*?)\[/red\]#si', '<span style="color:red">\1</span>', $var );
	$var = preg_replace ( '#\[green\](.*?)\[/green\]#si', '<span style="color:green">\1</span>', $var );
	$var = preg_replace ( '#\[blue\](.*?)\[/blue\]#si', '<span style="color:blue">\1</span>', $var );
	return $var;
}

function antibb($var) {
	$var = preg_replace ( '#\[(.*?)\]#si', '', $var );
	$var = str_replace ( '\[', '', $var );
	$var = str_replace ( '\]', '', $var );
	return $var;
}
function showLP($pages) {
	if ($pages <= 7) {
		for($i = 1; $i <= $pages; $i ++) {
			if ($i == $_GET ['page'])
				echo '[<b>' . $i . '</b>]';
			else
				echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
			if ($i != $pages)
				echo ',';
		}
	} else {
		if ($_GET ['page'] <= 2 || $_GET ['page'] >= $pages - 2) {
			if ($_GET ['page'] == 1 || $_GET ['page'] == $pages) {
				for($i = 1; $i <= 2; $i ++) {
					if ($i == $_GET ['page'])
						echo '[<b>' . $i . '</b>]';
					else
						echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
					if ($i != 2)
						echo ',';
				}
				echo '..';
				for($i = $pages - 1; $i <= $pages; $i ++) {
					if ($i == $_GET ['page'])
						echo '[<b>' . $i . '</b>]';
					else
						echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
					if ($i != $pages)
						echo ',';
				}
			} else {
				if ($_GET ['page'] <= 2) {
					for($i = 1; $i <= $_GET ['page'] + 1; $i ++) {
						if ($i == $_GET ['page'])
							echo '[<b>' . $i . '</b>]';
						else
							echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
						if ($i != $_GET ['page'] + 1)
							echo ',';
					}
					echo '..';
					for($i = $pages - 1; $i <= $pages; $i ++) {
						if ($i == $_GET ['page'])
							echo '[<b>' . $i . '</b>]';
						else
							echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
						if ($i != $pages)
							echo ',';
					}
				} else {
					for($i = 1; $i <= 2; $i ++) {
						if ($i == $_GET ['page'])
							echo '[<b>' . $i . '</b>]';
						else
							echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
						if ($i != $_GET ['page'] + 1)
							echo ',';
					}
					echo '..';
					for($i = $_GET ['page'] - 1; $i <= $pages; $i ++) {
						if ($i == $_GET ['page'])
							echo '[<b>' . $i . '</b>]';
						else
							echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
						if ($i != $pages)
							echo ',';
					}
				}
			}
		} else {
			$i = 1;
			if ($_GET ['page'] - 2 == 1)
				$p = ',';
			else
				$p = '..';
			echo '<a href="?page=' . $i . $u . '">' . $i . '</a>' . $p;
			
			//
			

			for($i = $_GET ['page'] - 1; $i <= $_GET ['page'] + 1; $i ++) {
				if ($i == $_GET ['page'])
					echo '[<b>' . $i . '</b>]';
				else
					echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
				if ($i != $_GET ['page'] + 1)
					echo ',';
			}
			echo '..';
			//
			

			$i = $pages;
			echo '<a href="?page=' . $i . $u . '">' . $i . '</a>';
		}
	}
}
function tags($idg) {
	$sql = mysql_fetch_row ( mysql_query ( "select tieude from game where id=$idg" ) ) or die ( mysql_error () );
	$tags = '';
	$total_tag = substr_count ( $sql [0], ' ' ) + 1;
	if ($total_tag > 0) {
		for($t = 0; $t < $total_tag; $t ++) {
			$keyword = explode ( ' ', $sql [0] );
			$tags .= '<a href="' . $set ['home'] . '/game/tim.php?key=' . $keyword [$t] . '">' . str_replace ( '-', ' ', $keyword [$t] ) . '</a>';
			if ($t < $total_tag - 1)
				$tags .= '|';
		}
	}
	return $tags;
}

/**
 * Lấy đuôi file
 * @param string $name <p>
 * Tên file đi kèm
 * </p>
 * @return string Trả về đuôi file
 */
function getExt($name) {
	return end ( explode ( '.', $name ) );
}

/**
 * Kiểm tra đuôi file thuộc loại nào trong số các loại: jar, sis, apk
 */
function cgame($name) {
	$exts [] = 'jar';
	$exts [] = 'JAR';
	$exts [] = 'sis';
	$exts [] = 'SIS';
	$exts [] = 'apk';
	$exts [] = 'APK';
	$found = false;
	foreach ( $exts as $key => $value ) {
		if (getExt ( $name ) == $value) {
			$found = true;
			break;
		}
	}
	if (! $found)
		return false;
	else
		return true;
}
function p20repl($fn) {
	return str_replace ( '%20', '-', $fn );
}
function getWithoutPath($filename) {
	return end ( explode ( "/", $filename ) );
}
function cmail($email) {
	if (strlen ( $email ) == 0)
		return false;
	if (eregi ( "^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", $email ))
		return true;
	return false;
}

$ip = $_SERVER ['REMOTE_ADDR'];
$url = $_SERVER ['PHP_SELF'];
$dt = $_SERVER ['HTTP_X_OPERAMINI_PHONE'];
$dt = str_replace ( '#', '', $dt );
if ($dt) {
	$dt = $dt;
} else {
	$dt = 'Khách';
}
$dspam = time () - 15;
@mysql_query ( "delete from spam where time<'" . $dspam . "'" );
$ton = time ();
$thet = time () - 900;
@mysql_query ( "delete from online where time<'" . $thet . "'" );
$kton = mysql_result ( mysql_query ( "select count(*) from online where ip = '" . $ip . "' and dt = '" . $dt . "'" ), 0 );
if ($user_id) {
	$ten = $taikhoan ['nick'];
} else {
	$ten = 'Khách';
}
if ($kton == 0) {
	@mysql_query ( "INSERT INTO `online` SET `ten` = '" . $ten . "', `dt` = '" . $dt . "', `url` = '" . $url . "', `ip` = '" . $ip . "', `time` = '" . $ton . "'" );
} else {
	$con = mysql_fetch_array ( mysql_query ( "select * from online where dt='" . $dt . "' and ip ='" . $ip . "'" ) );
	if ($con ['url'] != $url) {
		@mysql_query ( "UPDATE `online` SET `url` = '" . $url . "' where dt='" . $dt . "' and ip = '" . $ip . "'" );
	}
	@mysql_query ( "UPDATE `online` SET `time` = '" . $ton . "' where dt='" . $dt . "' and ip = '" . $ip . "'" );
}
?>